package com.memory.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.memory.common.R;
import com.memory.dao.EmployeeDao;
import com.memory.daomain.Employee;
import com.memory.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 邓哈哈
 * 2023/1/11 18:47
 * Function:
 * Version 1.0
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeDao, Employee> implements EmployeeService {
    @Autowired
    private EmployeeDao employeeDao;

    /**
     * 分页查询
     * 条件查询
     *
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public Page getPage(Integer page, Integer pageSize, String name) {
        //1.封装Page对象
        Page<Employee> pageInfo = new Page(page, pageSize);

        //2.设置查询条件
        LambdaQueryWrapper<Employee> lqw = new LambdaQueryWrapper<>();
        lqw.like(!StringUtils.isEmpty(name), Employee::getName, name);
        lqw.orderByDesc(!StringUtils.isEmpty(name), Employee::getUpdateTime);

        //3.执行分页查询
        employeeDao.selectPage(pageInfo, lqw);

        return pageInfo;
    }
}
